﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class Wall : MonoBehaviour
{
    public int wallType = 0;
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.layer == 10 || (other.gameObject.layer == 11 && other.GetComponent<Enemy>() != null && other.GetComponent<Enemy>().enemyType == Enemy.EnemyType.Fat))
        {
            if (transform.parent.GetComponent<WallParent>() != null)
                transform.parent.GetComponent<WallParent>().PengZhuang();
            StartCoroutine(PlayerScale(other));
        }
    }

    private float scaleTime = 0.15f;
    IEnumerator PlayerScale(Collider other)
    {
        other.gameObject.GetComponent<Player>().moveSpeed = 0f;
        Vector3 v = other.GetComponent<IReflector>().GetDir();
        Vector3 toV = Vector3.Reflect(v, transform.forward);
        //other.gameObject.transform.DOLookAt(transform.position + toV, scaleTime);
        other.gameObject.transform.DOScale(new Vector3(1.5f, 1.5f, 0.5f), scaleTime);
        yield return new WaitForSeconds(scaleTime);
        other.gameObject.transform.DOScale(new Vector3(1f, 1f, 1f), scaleTime);
        other.GetComponent<IReflector>().SetDir(toV);
        other.GetComponent<Player>().moveSpeed = 30f;
    }

    public Vector3 GetTheOtherPoint(Vector3 start, Vector3 end)
    {
        Vector3 v1 = end - start;
        Vector3 v2 = Vector3.Reflect(v1, transform.forward);
        return end + v2;
    }
}